<template>
  <div>
    <el-row :gutter="20" type="flex">
      <el-col :span="6">
        <el-input
          placeholder="请输入书籍名称"
          v-model="listQueryIn.title"
          clearable
          size="small"
        >
        </el-input>
      </el-col>
      <el-col :span="12">
        <btn-search @click.native="refreshList()"></btn-search>
        <btn-delete
          :disabled="multipleSelection.length == 0"
          @click.native="handleBatchDelete()"
        ></btn-delete>
        <!-- <el-button type="primary" size="small" @click="handlePdf"
          >pdf预览</el-button
        > -->
        <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-download"
          @click="handleImport"
          >导入书籍</el-button
        > -->
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { throttle } from 'lodash'
export default {
  data() {
    return {
      multipleSelection: [],
      listQueryIn: {
        title: '',
      },
    }
  },
  props: ['curColumn'],
  watch: {
    curColumn: {
      handler() {
        this.multipleSelection = []
      },
    },
  },
  mounted() {
    this.$bus.$on('deleteBatchJournal', (v) => {
      this.multipleSelection = v
    })
  },
  beforeDestroy() {
    this.$bus.$off('deleteBatchJournal')
  },
  methods: {
    handleInput: throttle(function () {
      this.refreshList()
    }, 2000),
    refreshList() {
      this.$bus.$emit('refreshJournalList', this.listQueryIn)
    },
    //批量删除
    handleBatchDelete() {
      if (!this.multipleSelection.length) {
        this.warnMsg('请选择要删除的数据')
        return
      }
      this.deleteTips(this.deleteAll)
    },
    //批量删除
    async deleteAll() {
      let { msg } = await this.$store.dispatch(
        'deleteBatchSysJournal',
        this.multipleSelection,
      )
      if (msg && msg != '成功') {
        this.warnMsg(msg)
      }
      this.$bus.$emit('refreshJournalList')
      this.multipleSelection = []
    },
    handlePdf() {
      let routeUrl = this.$router.resolve({ name: 'pdfPreview' })
      window.open(routeUrl.href, '_blank')
    },
    handleImport() {
      this.$bus.$emit('showImportSysJournal')
    },
  },
}
</script>